package org.lem

class ClassSchedule {

  String classId
  String schoolYear =  new Date().getYear() + 1900
  Location location
  SkillLevel level
  ClassSession session
  ClassTime classTime
  Integer classDuration = 3
  ClassDay classDay
    
  static belongsTo = [location:Location]
  
  static constraints = {
  	classId(editable:false)
  	schoolYear(blank:false)
  	location(blank:false)
  	level(blank:false)
  	classDay(blank:false)
  	session(blank:true, nullable:true)
  	classTime(blank:false)
  	
  	classDuration(blank:false)
  }
  
  def beforeInsert = {
  	classId = "${location}${schoolYear}${classDay}${classTime}${level}"
	if(session != null){
		classId += "${session}"
	}
  }
  
  def beforeUpdate = {
  	classId = "${location}${schoolYear}${classDay}${classTime}${level}"
	if(session != null){
		classId += "${session}"
	}

  }

	
  String toString () {
      "${classId}"
  }

}
